package mao.thinkinjava.io.serialize;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.List;

public class CADStateStore {
    public static void main(String[] args) throws Exception{
        ArrayList<Shape> shape = new ArrayList<Shape>();
        for (int i = 0; i < 10; i++) {
            shape.add(Shape.randomFactory());
        }
        for (int i = 0; i < 3; i++) {
            shape.get(i).setColor(Shape.RED);
        }
        ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("cadStateStore"));
        out.writeObject(shape);
        for (int i = 0; i < 3; i++) {
            shape.get(i).serializeStaticField(out);
        }
        System.out.println(shape);

        ObjectInputStream in = new ObjectInputStream(new FileInputStream("cadStateStore"));
        List<Shape> shapeList = (List<Shape>) in.readObject();
        System.out.println(shapeList);
    }
}
